package com.software.levelupserver.controller;

import com.software.levelupserver.entity.Badge;
import com.software.levelupserver.service.BadgeService;
import com.software.levelupserver.utils.ResultVOUtil;
import com.software.levelupserver.vo.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/badge")
public class BadgeController {
    @Resource
    private BadgeService badgeService;

    /**
     * 获取用户获得的所有徽章
     * @return
     */
    @GetMapping("/getAllBadgeByUserId")
    public Result getAllBadgeByUserId(){
        List<Badge> badgeList = badgeService.getAllBadgeByUserId();

        if (badgeList != null){
            return ResultVOUtil.success(badgeList);
        }else {
            return ResultVOUtil.error("获取徽章失败");
        }
    }

    /**
     * 获取用户获得徽章中某种类型的最高等级徽章
     * @param badgeType
     * @return
     */
    @GetMapping("/getBadgeByTypeAndUserId")
    public Result getBadgeByTypeAndUserId(int badgeType){
        Badge badge = badgeService.getBadgeByTypeAndUserId(badgeType);
        if (badge == null || badge.getBadgeId() != 0){
            return ResultVOUtil.success(badge);
        }else {
            return ResultVOUtil.error("获取徽章失败");
        }
    }

    @GetMapping("/getAllBadge")
    public Result getAllBadge(){
        List<Badge> allBadge = badgeService.getAllBadge();
        if (allBadge != null)
            return ResultVOUtil.success(allBadge);
        else
            return ResultVOUtil.error("获取数据失败");
    }
}
